package com.ifast.asset.Thread;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.ifast.asset.domain.TaskrecordDO;
import com.ifast.asset.service.TaskrecordService;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.SimpleDateFormat;
import java.util.List;

public class SetAssetStatus implements Runnable {

    private TaskrecordService taskrecordService;
    public SetAssetStatus(TaskrecordService taskrecordService){

        this.taskrecordService = taskrecordService;
    }

    @Override
    public void run() {

        //System.out.println("执行定时扫描,将一个小时以前没有检测完毕的任务设置状态为扫描失败==================================");
        DateTime now = new DateTime();
        now = now.plusHours(-2);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = sdf.format(now.getMillis());
        Wrapper<TaskrecordDO> wrapper = new EntityWrapper();
        wrapper.le("time",format);
        wrapper.eq("status",0);
        //设置  任务的运行状态
        List<TaskrecordDO> taskrecords = taskrecordService.selectList(wrapper);
        for (int i= 0 ; i < taskrecords.size() ; i++){
            TaskrecordDO taskrecordDO = taskrecords.get(i);
            taskrecordDO.setStatus(-1);
            taskrecordService.updateById(taskrecordDO);
            System.out.println(taskrecordDO.getTime());
        }
    }
}
